const https = require('https');
const fs = require('fs');
const path = require('path');

const modelUrl = 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/SimpleSparseAccessor/glTF/SimpleSparseAccessor.gltf';
const modelPath = path.join(__dirname, 'public', 'models');

if (!fs.existsSync(modelPath)) {
  fs.mkdirSync(modelPath, { recursive: true });
}

const downloadFile = (url, filename) => {
  const filepath = path.join(modelPath, filename);
  const file = fs.createWriteStream(filepath);

  https.get(url, (response) => {
    response.pipe(file);
    file.on('finish', () => {
      file.close();
      console.log(`Downloaded ${filename}`);
    });
  }).on('error', (err) => {
    fs.unlink(filepath);
    console.error(`Error downloading ${filename}: ${err.message}`);
  });
};

downloadFile(modelUrl, 'human.gltf'); 